"""
用@property构造getter访问器和setter修改器来访问和修改私有属性。

version: 0.1
aurthor: Harry
"""

class Person(object):

    def __init__(self, name, age):
        self._name = name
        self._age = age

    # 访问器 -- getter方法
    @property
    def age(self):
        return self._age

    @property 
    def name(self):
        return self._name

    # 修改器 --setter方法
    @age.setter 
    def age(self, age):
        self._age = age
    
    def play(self):
        if self._age <= 16:
            print("%s正在玩飞行棋。" % self._name)
        else:
            print("%s正在玩斗地主。" % self._name)
    
def main():
    person = Person('王大锤', 12)
    person.play()
    person.age =  22
    person.play()
    # person._name = '白元芳' # AttributeError: can's set attribute
            
if __name__ == "__main__":
    main()
    